package com.zy.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * [登陆拦截器.session]
 *
 * @author : [张宇]
 * @version : [v1.0]
 * @createTime : [2024/12/12 19:47]
 */
//@Component
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 1.判断是否需要拦截(ThreadLocal中的用户)
        if (UserHolder.getUser() == null) {
            // 没有,拦截,设置状态码
            response.setStatus(401);
            return false;
        }
        // 2.由用户,则放行
        return true;
    }


}
